package com.ruoyi.web.controller.system;


import cn.hutool.core.util.StrUtil;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.page.ResponseResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.biz.BankBizService;
import com.ruoyi.system.domain.Bank;
import com.ruoyi.system.service.BankService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@Api(tags = "管理后台:收款方式相关接口")
@RestController
@RequestMapping("/admin/bank")
public class AdminBankController extends AdminController {


    @Resource
    private BankService bankService;

    @Resource
    private BankBizService bankBizService;


    @ApiOperation(value = "余额明细")
    @GetMapping("list")
    public ResponseResult<List<Bank>> list(Bank bank) {
        this.checkAdmin();
        this.startPage();

        List<Bank> list = bankService.findList(bank);
        return this.setSuccessResult(this.getPageResult(list));
    }

    @ApiOperation(value = "余额明细")
    @GetMapping("getById")
    public ResponseResult getById(Long id) {
        Bank byId = bankService.getById(id);
        return this.setSuccessResult(byId);
    }

    @ApiOperation(value = "列表")
    @GetMapping("bankList")
    public ResponseResult<List<Bank>> bankList(Bank bank) {


        if (StrUtil.isBlank(bank.getType())) {
            bank.setType(null);
        }
        this.startPage();
        List<Bank> list = bankService.findList(bank);
        return this.setSuccessResult(this.getPageResult(list));
        // return this.setSuccessResult(list);
    }

    @Log(title = "银行卡管理-启用/禁用", businessType = BusinessType.UPDATE)
    @ApiOperation(value = "启用/禁用")
    @PostMapping("updateStatus")
    public ResponseResult updateStatus(@RequestBody Bank bank) {
        this.checkAdmin();
        bankService.updateDomain(bank);
        return this.setSuccessResult();
    }
    @Log(title = "银行卡管理-新增或修改", businessType = BusinessType.UPDATE)
    @ApiOperation(value = "新增或修改")
    @PostMapping("save")
    public ResponseResult save(@RequestBody Bank bank) {
        this.checkAdmin();
        bankBizService.save(bank);
        return this.setSuccessResult();
    }


}
